package org.lds.scheduled.job.worker.service.impl;

import lombok.RequiredArgsConstructor;
import org.lds.scheduled.job.common.model.AddJobModel;
import org.lds.scheduled.job.common.model.RemoveJobModel;
import org.lds.scheduled.job.common.model.dto.ResultDTO;
import org.lds.scheduled.job.common.model.request.AddJobRequest;
import org.lds.scheduled.job.common.model.request.RemoveJobRequest;
import org.lds.scheduled.job.worker.listener.JobListeners;
import org.lds.scheduled.job.worker.service.ReceiveJobService;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class ReceiveJobServiceImpl implements ReceiveJobService {
    private final JobListeners jobListeners;

    @Override
    public ResultDTO addJob(AddJobRequest request) {
        for (AddJobModel addJobModel : request.getAddJobModels()) {
            jobListeners.publishAddJob(addJobModel);
        }
        return ResultDTO.success();
    }

    @Override
    public ResultDTO removeJob(RemoveJobRequest request) {
        for (RemoveJobModel removeJobModel : request.getRemoveJobModels()) {
            jobListeners.publishRemoveJob(removeJobModel);
        }
        return ResultDTO.success();
    }

}
